package com.gogonow.beetl.chapter2.expression;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;
import org.beetl.core.resource.FileResourceLoader;

public class ObjAndCollExpression {
	
	public static void main(String[] args) throws IOException{
		String root = System.getProperty("user.dir")+File.separator+"src/main/resources/template";
		FileResourceLoader fileLoader = new FileResourceLoader(root, Charset.forName("UTF-8").name());
		Configuration conf = Configuration.defaultConfiguration();
		GroupTemplate gt = new GroupTemplate(fileLoader, conf);
		Template template = gt.getTemplate("beetl-el.txt");
		template.binding("user",new User("zhuzl","男"));
		
		
		List<User> list = new ArrayList<ObjAndCollExpression.User>();
		list.add(new User("zhuzl1", "男"));
		list.add(new User("zhuzl2", "男"));
		list.add(new User("zhuzl3", "女"));
		
		template.binding("list", list);
		
		
		System.out.println(template.render());
		
	}
	
	public static class User{
		public String name;
		public String sex;
		
		public User(String name,String sex){
			this.name = name;
			this.sex = sex;
		}
		
		public Object get(String name){
			return "hehe";
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getSex() {
			return sex;
		}

		public void setSex(String sex) {
			this.sex = sex;
		}
	}
	

}
